package hoi.addrbook.ui;

import java.awt.BorderLayout;
import java.awt.Font;
import java.util.Enumeration;

import hoi.addrbook.img.ImageHelper;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

public class AddrBookFrame extends JFrame {

	private static final long serialVersionUID = -3116155141455555134L;

	public static final String TITLE = "海石通讯录";

	public AddrBookFrame() {
		try {
			SwingUtilities.invokeAndWait(new Runnable() {
				public void run() {
					setLayout(new BorderLayout());
					add(new AddrBookPanel(), BorderLayout.CENTER);
				}
			});
		} catch (Exception exc) {
			System.err.println("Can't create because of " + exc);
		}
	}

	private static void setLookAndFeel(String lnfName) {
		try {
			com.jtattoo.plaf.acryl.AcrylLookAndFeel.setTheme("Lemmon", "??", "Hoi");
			UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
		} catch (Exception exc) {
			System.err.println("Could not load LookAndFeel: " + lnfName);
		}
	}

	private static void initGlobalFontSetting(Font fnt) {
		FontUIResource fontRes = new FontUIResource(fnt);
		for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
			Object key = keys.nextElement();
			Object value = UIManager.get(key);
			if (value instanceof FontUIResource)
				UIManager.put(key, fontRes);
		}
	}

	public static void main(String[] args) {
		setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
		initGlobalFontSetting(new Font("Dialog", Font.PLAIN, 12));
		AddrBookFrame frame = new AddrBookFrame();
		frame.setSize(600, 450);
		frame.setLocationRelativeTo(null);
		frame.setResizable(false);
		frame.setTitle(TITLE);
		frame.setIconImage(ImageHelper.ICON_LOGO.getImage());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}
